package com.linewow.xhyy.hrxb.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.linewow.xhyy.hrxb.entity.NiHaoInfo;
import com.linewow.xhyy.hrxb.NiHaoNetWork;
import com.linewow.xhyy.nihaonew.R;

import com.linewow.xhyy.nihaonew.application.NiHaoApp;
import com.linewow.xhyy.nihaonew.base.BaseFragmentActivity;
import com.linewow.xhyy.nihaonew.event.MessageEvent;

import org.simple.eventbus.EventBus;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import rx.Observer;
import rx.schedulers.Schedulers;


/**
 * Created by LXR on 2016/8/26.
 */
public class ChatActivity extends BaseFragmentActivity {
//    private ChatFragment chatFragment;
    private String TAG="ChatActivity";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);
        initView();
    }

    public void initView() {
//        chatFragment=new ChatFragment();
//        chatFragment.setArguments(getIntent().getExtras());
//        getSupportFragmentManager().beginTransaction().add(R.id.chat_main,chatFragment).commit();
        String id=getIntent().getStringExtra("userId");
        Log.e(TAG,"ID"+id);

        String string= NiHaoApp.token;
        String str=null;
        try {
             str= URLEncoder.encode(string,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

//        final EaseUser user= EaseUserUtils.getUserInfo(id);


        NiHaoNetWork.getNihaoService().getNihaoInfo1(id,str)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .subscribe(new Observer<NiHaoInfo>() {
                    @Override
                    public void onCompleted() {
                        Log.e(TAG,"完成了--->");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e(TAG,"error--->"+e.getMessage());
                    }

                    @Override
                    public void onNext(NiHaoInfo niHaoInfo) {
//                        user.setAvatar(niHaoInfo.head_img);
//                        user.setNick(niHaoInfo.nickname);
//                        DemoHelper.getInstance().saveContact(user);
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().post(new MessageEvent(),TAG);
    }
}
